package com.app.couponsharelife.ui.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.viewpager.widget.PagerAdapter
import com.app.couponsharelife.R
import com.app.couponsharelife.ui.main.WelcomeActivity

/**
 * Created by guluwa on 2018/11/28.
 */
class WelcomeViewAdapter(val activity: WelcomeActivity, val list: List<Any>) : PagerAdapter() {

    override fun isViewFromObject(p0: View, p1: Any): Boolean {
        return p0 == p1
    }

    override fun getCount(): Int {
        return list.size
    }

    override fun instantiateItem(container: ViewGroup, position: Int): Any {
        val view = LayoutInflater.from(container.context)
                .inflate(R.layout.welcome_view_item, container, false)
        when (position) {
            0 -> view.setBackgroundResource(R.drawable.ic_welcome_page1)
            1 -> view.setBackgroundResource(R.drawable.ic_welcome_page2)
            2 -> view.setBackgroundResource(R.drawable.ic_welcome_page3)
            else -> view.setBackgroundResource(R.drawable.ic_welcome_page3)
        }
        container.addView(view)
        return view
    }

    override fun destroyItem(container: ViewGroup, position: Int, any: Any) {
        container.removeView(any as View)
    }
}